<?php

namespace app\super\controller;

use think\Controller;
use think\Db;

/**
 * ajax 异步加载页面
 * Class Ajax
 * @package app\admin\controller
 */
class AjaxController extends CommonController {
    /**
     * 仪表盘
     */
    public function dashboard() {
        $info = Db::table('up_u_bill')
            ->field('bill_money,bill_money_type,bill_type,bill_state')
            ->select();

        //收益
        $earning = 0;
        //支出
        $spend = 0;
        //收入
        $income = 0;
        foreach($info as $key=>$vo){
            if($vo['bill_money_type']=='4'  && $vo['bill_type']=='1'){
                $earning = $earning + $vo['bill_money'] * 0.1;
            }
            if($vo['bill_state']=='2' && $vo['bill_type']=='1' && $vo['bill_money_type']!=='1'){
                $spend = $spend + $vo['bill_money'];
            }elseif($vo['bill_state']=='1' && $vo['bill_type']=='1'){
                $income = $income + $vo['bill_money'];
            }
        }
        $amount = $income - $spend;
        $this->assign('earning',$earning);
        $this->assign('amount',$amount);
        return $this->fetch('dashboard/manage');
    }
    /***
     * 用户管理
     */
    public function user(){
        return $this->fetch('user/manage');

    }

    /**
     * 团队信息管理
     */
    public function course_manage() {
        $team_status = '';
        if(isset($_GET['team_status'])){
            $team_status = $_GET['team_status'];
        }
        $this->assign('team_status',$team_status);
        return $this->fetch('course/manage');
    }
    /**
     * 团队公告
     */
//    public function class_manage() {
//        return $this->fetch('course/manageadv');
//    }
    /**
     * 团队任务
     * @return mixed
     */
    public function course_arrange() {
        return $this->fetch('course/release');
    }



    /**
     * @return mixed
     * 成员管理
     */
    public function project(){
        return $this->fetch('member/manage');

    }

    /**
     * 生活管理
     */
//    public function student(){
//
//        return $this->fetch('life/manage');
//    }
    /**
     * 生活资讯管理
     */
    public function life_list(){
        $where['region_fid'] = 'ZDvaTNytyem97oNtRh692WpwYW8C3YPr';
        $res = Db::table('up_dic_region')->where($where)->select();
        $this->assign('res',$res);
        return $this->fetch('life/manage');

    }


    /**
     * financial_management 财务管理 
     * @return 展示财务管理页面
    */
    public function financial_management(){
        return $this->fetch('money/manage');

    }

    /***
     * 生活评论
     */
    public function life_comment(){
        return $this->fetch('comment/manage');
    }

    public function life_classification(){
        return $this->fetch('life/classification');
    }
    /**
     * 学习管理 - 课程管理-发布课程
     * @return mixed
     */
    public function subject_manage() {
        return $this->fetch('study/manage');
    }

    /***
     * 学习管理 - 课程管理-发布目录
     */
    public function lunbo_manage(){
        $project_id = $_GET['project_id'];
        $this->assign('project_id',$project_id);
        $project_release_user_id = Db::table('up_project')->where('project_id',$project_id)->value('project_release_user_id');
        $uid = session('loginSession')['user_id'];
        if($project_release_user_id==$uid){
            $this->assign('project_user_status',1);
        }else{
            $this->assign('project_user_status',2);
        }
        return $this->fetch('study/catalog');

    }

    /***
     * 学习管理-课程管理-发布目录视频
     */
    public function advert_manage(){
        $uid = session('loginSession')['user_id'];

        $video_id = $_GET['video_id'];
        $this->assign('video_id',$video_id);
        $catalog_project_id = Db::table('up_project_catalog')->where('catalog_id',$video_id)->value('catalog_project_id');
        if($catalog_project_id!=''){
            $project_release_user_id = Db::table('up_project')->where('project_id',$catalog_project_id)->value('project_release_user_id');
            if($project_release_user_id==$uid){
                $this->assign('project_user_status',1);
            }else{
                $this->assign('project_user_status',2);
            }
        }

        return $this->fetch('study/video');
    }



    /**
     * 学习管理-书籍管理 -
     */

    public function goodat_manage(){
        return $this->fetch('book/manage');
    }

    /**
     * 学习管理 - 书籍目录
     */
    public function personal_settings(){
        $book_id = $_GET['book_id'];
        $this->assign('book_id',$book_id);
        $uid = session('loginSession')['user_id'];
        $book_send_publisher_id = Db::table('up_book')->where('book_id',$book_id)->value('book_send_publisher_id');
        if($book_send_publisher_id==$uid){
            $this->assign('project_user_status',1);
        }else{
            $this->assign('project_user_status',2);
        }
        return $this->fetch('book/catalog');
    }

    /**
     * 学习管理 - 培训试题管理
     */
    public function classtime_manage(){
        return $this->fetch('train/manage');
    }

    /**
     * 学习管理 - 题目管理
     */
    public function global_config(){
        $exam_id = $_GET['exam_id'];
        $this->assign('exam_id',$exam_id);
        return $this->fetch('subject/manage');

    }
    /**
     * 学习管理 -知识库管理
     */
    public function common_settings(){
        return $this->fetch('knowledge/manage');
    }
    /**
     * 菜单管理
     */
    public function menu_manage() {
        return $this->fetch('menu/manage');
    }

    /**
     * @return mixed意见反馈
     */
    public function feedback(){
        return $this->fetch('other/feedback');
    }

    /**
     * @return mixed版本管理
     */
    public function edition(){
        return $this->fetch('other/edition');
    }

    /**
     * @return mixed 规则配置
     */
    public function rule(){
        return $this->fetch('other/rule');
    }
    /**
     * @return mixed系统管理
     */
    public function system(){
        return $this->fetch('other/system');

    }
    /**
     * @return mixed系统管理
     */
    public function industry(){
        return $this->fetch('other/industry');

    }

    /**
     * 广告管理
     */
    public function advert(){
        $adv_status = '';
        if(isset($_GET['adv_status'])){
            $adv_status = $_GET['adv_status'];
        }
        $this->assign('adv_status',$adv_status);
        return $this->fetch('advert/manage');
    }
    /**
     * 广告分类管理
     */
    public function advert_type(){
        return $this->fetch('advertisement/manage');
    }

    /**
     * 用户列表
     */
    public function user_list(){
        return $this->fetch('management/manage');
    }

}
